﻿<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>

<? if (strlen($arResult["ERROR"])>0) : ?>
    <?= $arResult["ERROR"]; ?>
<? elseif (strlen($arResult["SUCCESS"])>0) : ?>
    <?= $arResult["SUCCESS"]; ?>
<? else: ?>    
<form action="<?= $APPLICATION->GetCurPage(); ?>" method="POST" name="f" onsubmit="return checkform(f);" enctype="multipart/form-data">
    <input name="MAX_FILE_SIZE" value="52428800" type="hidden"/>
    <input type="hidden" name="FORMTYPE" value="newrequest" />
        
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <? if ($arResult["ISADMIN"] || $arResult["ISPERFORMER"]): ?>
        <tr>
            <td class="tblzag" nowrap>Создать от пользователя:</td>
            <td class="tbltxt">
                <select name="author">
                    <option value="0"></option>
                    <? foreach ($arResult["CLIENTS"] as $client): ?>
                    <option value="<?= $client["ID"]; ?>"><?= $client["LAST_NAME"]." ".$client["NAME"]; ?></option>
                    <? endforeach; ?>
                </select>
            </td>
        </tr>        
        <? endif; ?>
        
        <? if (count($arResult["CATEGORY"])): ?>
        <tr>
            <td class="tblzag" nowrap><span class="red">*</span> Категория обращения:</td>
            <td class="tbltxt">
                <select name="category">
                    <option value="0">выберите категорию...</option>
                    <? foreach ($arResult["CATEGORY"] as $key => $value): ?>
                    <option value="<?= $key; ?>"><?= $value; ?></option>
                    <? endforeach; ?>
                </select>
            </td>
        </tr>
        <? endif; ?>
        
        <? if (($arParams["USE_PROJECT"]=="Y") && count($arResult["PROJECT"])): ?>
        <tr>
            <td class="tblzag" nowrap>Проект:</td>
            <td class="tbltxt">
                <select name="project">
                    <option value="0"></option>
                    <? foreach ($arResult["PROJECT"] as $key => $value): ?>
                    <option value="<?= $key; ?>"><?= $value; ?></option>
                    <? endforeach; ?>
                </select>
            </td>
        </tr>
        <? endif; ?>
        
        <tr>
            <td class="tblzag" nowrap><span class="red">*</span> Заголовок:</td>
            <td class="tbltxt"><input type="text" name="zag" class="inpzag" /></td>
        </tr>

        <tr>
            <td class="tblzag" nowrap><span class="red">*</span> Сообщение:</td>
            <td class="tbltxt"><textarea name="request" cols="60" rows="10"></textarea></td>
        </tr>

        <? if (count($arResult["CRITICALITY"])): ?>
        <tr>
            <td class="tblzag" nowrap>Критичность:</td>
            <td class="tbltxt">
                <select name="criticality">
                    <option value="0"></option>
                    <? foreach ($arResult["CRITICALITY"] as $key => $value): ?>
                    <option value="<?= $key; ?>"><?= $value; ?></option>
                    <? endforeach; ?>
                </select>
            </td>
        </tr>
        <? endif; ?>
        
        <tr>
            <td class="tblzag" nowrap>Прикрепить файлы:</td>
            <td class="tbltxt">
                <input type="hidden" name="lastfile" id="lastfile" value="file_1_" />
                <div id="fileslist">
                <input type="file" onchange="addNewRow(this)" name="file_1_" id="file_1_" /><br />
                </div>
            </td>
        </tr>
        
        <tr>
            <td class="tblzag"></td>
            <td class="tbltxt"><div class="h20"></div><input type="submit" value="Отправить" /></td>
        </tr>
        
    </table>
    
</form>
<? endif; ?>

    <div class="h40"></div>
    <a href="<?= str_replace("add/", "", $APPLICATION->GetCurPage()); ?>">Вернуться к списку заявок</a><br />    

    
<script language="JavaScript">    
function checkform(f)
{    
    if (f.category.value==0)
    {
        alert('Необходимо указать категорию!');
        return false;
    }
    else
    if (f.request.value.length==0)        
    {
        alert('Необходимо написать обращение!');
        return false;
    }
        
    return true;
}

function addNewRow(el)
{    
    if (el.id == document.getElementById('lastfile').value)
    {
        //if (el.id==document.getElementById('lastfile').textContent )
        var nHTML = "";
        var div = document.getElementById('fileslist');
        var sHTML=div.innerHTML;
        var p = sHTML.length;
        var s = sHTML.lastIndexOf('file_',p);
        if(s<0)return false;
        var e = sHTML.lastIndexOf('_"',p);
        if(e<0)return false;
        var n = parseInt(sHTML.substr(s+5,e-s));
        var descid = 'desc_'+n;
        var newid = 'file_'+(++n)+'_';
        nHTML = nHTML+'<br /><input type="file" onchange="addNewRow(this)" name="'+newid+'" id="'+newid+'" /><br />';
        var newDiv = document.createElement('div');
        newDiv.innerHTML = nHTML;
        document.getElementById('fileslist').appendChild(newDiv);
        document.getElementById('lastfile').value = newid;
        //document.getElementById('fileslist').innerHTML += nHTML;
        
    }
}
</script>